#include "Common.h"
#include <QFile>
#include <QMessageBox>
#include <QTextStream>
#include <QXmlStreamWriter>

bool readFromFile(const QString &filename, QString &content, bool withEOL)
{
	QFile file(filename);
	if (!file.exists()) {
		return false;
	}

	if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
		return false;
	}

	QTextStream stream(&file);
	while (!stream.atEnd()) {
		content.append(stream.readLine());
		if (withEOL) {
			content.append('\n');
		}
	}

	file.close();

	return true;
}

bool writeToFile(const QString &filename, QString &content)
{
	QFile file(filename);
	if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
		return false;

	QTextStream out(&file);
	out << content << endl;

	file.close();

	return true;
}
